/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smary.managed.dependencies;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import smary.ejb.stateless.auto.*;

/**
 * Managedbean zur Abhängigkeitspruefung von Anzeige von Datenformularen.
 * Beispielsweise kann kein Productbacklog ohne Scrum Projekt angelegt werden.
 * In so einem Falle gibt public boolean entitySatisfied(String type) false zurueck.
 * @author ACANPOWER
 */
@Named(value = "entityDependenceService")
@ApplicationScoped
public class EntityDependenceService {

    @Inject
    ScrumprojektFacade scrumprojektFacade;
    
    @Inject
    ProductbacklogFacade productbacklogFacade;
    
    @Inject
    DefinitionofdoneFacade definitionofdoneFacade;
    
    @Inject
    ScrumteamFacade scrumteamFacade;
    
    @Inject
    UserstoryFacade userstoryFacade;
    
    @Inject
    SprintFacade sprintFacade;
            
    public EntityDependenceService() {
    }
    public boolean entitySatisfied(String type){
        if(type.equals("productbacklog") 
                || type.equals("definitionofdone")
                || type.equals("scrumteam")){
            if(scrumprojektFacade.count()>0)
                return true;
        }
        else if(type.equals("userstories")
                || type.equals("sprint")) {
            if(productbacklogFacade.count() > 0
                    && definitionofdoneFacade.count()> 0)
                return true;
        }
        else if(type.equals("user")){
            if(scrumteamFacade.count() > 0) return true;
        }
        else if(type.equals("task")){
            if(userstoryFacade.count() > 0
                    && sprintFacade.count() > 0)return true;
        }
        return false;
    }
}
